from unicodedata import category
from django.db import models

# Create your models here.
class BasicProductInfo(models.Model):
    product_code = models.CharField()
    product_name = models.CharField()
    status = models.CharField()
    category_code = models.CharField()
    category_detail_code = models.CharField()

    retail_type_code = models.CharField()
    unit = models.IntegerField()
    sales_point = models.FloatField()

    default_retail_price = models.FloatField()
    created_at = models.DateTimeField(auto_now_add=True)
    # retail_price_strategy = models.CharField()

    # default_sales = models.IntegerField()
    # sales_strategy = models.CharField()

    # default_purchase = models.IntegerField()
    # purchase_strategy = models.CharField()

class ProductPriceStrategy(models.Model):
    strategy_code = models.CharField()
    product_code = models.CharField()
    retail_price = models.DecimalField(max_digits=6, decimal_places=2)

class ProductSalesStrategy(models.Model):
    pass

class ProductPurchaseStrategy(models.Model):
    pass


class ProductsInventory(models.Model):
    product_code = models.CharField(unique=True, verbose_name='商品编码', db_index=True)
    instock_quantity = models.IntegerField(default=0, verbose_name='当前库存量')
    delivery_quantity = models.IntegerField(default=0, verbose_name='配送中数量')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        verbose_name = '库存'
        verbose_name_plural = '库存'
        indexes = [
            models.Index(fields=['product_code'])
        ]

    def __str__(self):
        return f"{self.product_code} - 当前库存: {self.instock_quantity}"

class ProductsInventorySnapshot(models.Model):
    product_code = models.CharField(verbose_name='商品编码', db_index=True)
    instock_quantity = models.IntegerField(default=0, verbose_name='当前库存量')
    delivery_quantity = models.IntegerField(default=0, verbose_name='配送中数量')
    inventory_date = models.DateField(verbose_name='库存日期')

    class Meta:
        verbose_name = '库存快照'
        verbose_name_plural = '库存快照'
        indexes = [
            models.Index(fields=['product_code', 'inventory_date'])
        ]
        # unique_together = ['product_code', 'inventory_date']  # 添加联合唯一约束

    def __str__(self):
        return f"{self.product_code} - {self.inventory_date} 库存: {self.instock_quantity}"






